//
//  LYQHomePublicationView.m
//  ZCProject
//
//  Created by Zheng on 2016/12/20.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQHomePublicationView.h"

#import "LYQMainTabBarController.h"
#import "LYQHomeNavigationController.h"

#import "LYQEditPositionViewController.h"

@implementation LYQHomePublicationView

- (instancetype)init {
    self = [super init];
    if (self) {
        
        self.backgroundColor = RGB(244, 244, 244, 0.95);
        
        [self addSubview:self.resourcesBtn];
        [self addSubview:self.positionBtn];
        [self addSubview:self.demandBtn];
        [self addSubview:self.activityBtn];
        [self addSubview:self.topicBtn];
        [self addSubview:self.cancelBtn];
        
        [self subviewsSetFrame];
        
    }
    return self;
}

#pragma mark - layout subviews
- (void)subviewsSetFrame {
    
    CGRect frame = CGRectMake(0, 0, kWScale(80), kWScale(80));
    
    _resourcesBtn.frame = frame;
    _resourcesBtn.center = CGPointMake(kMS_Width/2, kHScale(160));
    
    _positionBtn.frame = frame;
    _positionBtn.center = CGPointMake(kWScale(95), kHScale(240));
    
    _demandBtn.frame = frame;
    _demandBtn.center = CGPointMake(kMS_Width-kWScale(95), kHScale(240));
    
    _activityBtn.frame = frame;
    _activityBtn.center = CGPointMake(kWScale(130), kHScale(345));
    
    _topicBtn.frame = frame;
    _topicBtn.center = CGPointMake(kMS_Width-kWScale(130), kHScale(345));
    
    _cancelBtn.frame = CGRectMake(kWScale(45), kHScale(480)-kWScale(20), kMS_Width-kWScale(90), kWScale(40));

}

#pragma mark - lazy load subviews
- (UIButton *)resourcesBtn {
    if (_resourcesBtn) {
        return _resourcesBtn;
    }
    
    _resourcesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _resourcesBtn.layer.cornerRadius = kWScale(40);
    _resourcesBtn.backgroundColor = RGB(253, 141, 69, 1);
    [_resourcesBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    return _resourcesBtn;
}

- (UIButton *)positionBtn {
    if (_positionBtn) {
        return _positionBtn;
    }
    
    _positionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _positionBtn.layer.cornerRadius = kWScale(40);
    _positionBtn.backgroundColor = RGB(41, 187, 179, 1);
    [_positionBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    
    return _positionBtn;
}

- (UIButton *)demandBtn {
    if (_demandBtn) {
        return _demandBtn;
    }
    
    _demandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _demandBtn.layer.cornerRadius = kWScale(40);
    _demandBtn.backgroundColor = RGB(118, 195, 36, 1);
    [_demandBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    return _demandBtn;
}

- (UIButton *)activityBtn {
    if (_activityBtn) {
        return _activityBtn;
    }
    
    _activityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _activityBtn.layer.cornerRadius = kWScale(40);
    _activityBtn.backgroundColor = RGB(251, 100, 71, 1);
    [_activityBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    return _activityBtn;
}

- (UIButton *)topicBtn {
    if (_topicBtn) {
        return _topicBtn;
    }
    
    _topicBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _topicBtn.layer.cornerRadius = kWScale(40);
    _topicBtn.backgroundColor = kLYQBlue;
    [_topicBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    return _topicBtn;
}

- (UIButton *)cancelBtn {
    if (_cancelBtn) {
        return _cancelBtn;
    }
    
    _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [_cancelBtn setTitleColor:kLYQBlue forState:UIControlStateNormal];
    _cancelBtn.layer.cornerRadius = kWScale(20);
    _cancelBtn.layer.borderColor = [kLYQBlue CGColor];
    _cancelBtn.layer.borderWidth = kWScale(1.5);
    _cancelBtn.backgroundColor = RGB(244, 244, 244, 1);
    _cancelBtn.titleLabel.font = kWFont(16);
    [_cancelBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    return _cancelBtn;
}

#pragma mark - 取消事件
- (void)buttonAction:(UIButton *)sender {
    
    if (sender == _cancelBtn) {
    } else if (sender == _resourcesBtn) {
        NSLog(@"资源");
    } else if (sender == _positionBtn) {
        NSLog(@"招聘");
#pragma mark 跳转到职位编辑
        LYQEditPositionViewController *epVC = [[LYQEditPositionViewController alloc] init];
        epVC.hidesBottomBarWhenPushed = YES;        
        LYQMainTabBarController *mtbCtrl = (LYQMainTabBarController *)([UIApplication sharedApplication].keyWindow.rootViewController);
        LYQHomeNavigationController *hnCtrl = (LYQHomeNavigationController *)mtbCtrl.viewControllers[0];
        [hnCtrl pushViewController:epVC animated:YES];

        
    } else if (sender == _demandBtn) {
        NSLog(@"需求");
    } else if (sender == _activityBtn) {
        NSLog(@"活动");
    } else {
        NSLog(@"话题");
    }
    
    [UIView animateWithDuration:0.35 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];

}



@end
